package com.biz.dao.user.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import com.biz.dao.common.impl.GenericDAOImpl;
import com.biz.dao.user.UserDAO;
import com.biz.dto.user.RoleDTO;
import com.biz.dto.user.UserDTO;
@Repository("userDAOImpl")
public class UserDAOImpl extends GenericDAOImpl<UserDTO, String> implements UserDAO  {

	public UserDTO queryUserByName(String username) throws DataAccessException{
		return query(UserDTO.class, username);
	}

	@SuppressWarnings("unchecked")
	public List<RoleDTO> queryRoleByUser(String username) throws DataAccessException{
		List<UserDTO> user = getHibernateTemplate().find("from UserDTO u where u.username = ?",username);
		if(user!=null && user.size()>0){
			return  user.get(0).getRole();
		}else{
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<RoleDTO> queryAllRole() throws DataAccessException {
		List<RoleDTO> role = getHibernateTemplate().find("from RoleDTO");
		return role;
	}
	
}
